<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('上传代码并生成体验版')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-applet-commit">
        <input type="hidden" name="templateId"/>
        <input type="hidden" name="templateType"/>
        <input type="hidden" name="appletAppId" th:value="${appletInfo.appId}"/>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red; ">*</span>选择模板：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input type="text" id="templateDesc" class="form-control" required>
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red; ">*</span>小程序名称：</label>
            <div class="col-sm-7">
                <input class="form-control" type="text" th:value="${appletInfo.nickname}" disabled />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red; ">*</span>小程序AppId：</label>
            <div class="col-sm-7">
                <input class="form-control" type="text" th:value="${appletInfo.appId}" disabled />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red; ">*</span>版本号：</label>
            <div class="col-sm-4">
                <input class="form-control" name="userVersion" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span style="color: red; ">*</span>版本描述：</label>
            <div class="col-sm-7">
                <textarea name="userDesc" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-7">
                <span class="help-block m-b-none" style="color:red"><i class="fa fa-info-circle"></i>注意：体验版只会保留最新一条提交记录</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: bootstrap-suggest-js"/>

<script type="text/javascript">
    var prefix = ctx + "back/wechatOpen";

    //选择代码模板
    $("#templateDesc").bsSuggest({
        indexId: 1,
        indexKey: 0,
        keyField: "templateId",
        hideOnSelect: true,
        emptyTip: '<b>没有找到可用的代码模板</b>',
        effectiveFields: ["templateId", "templateType","sourceMiniProgram","userVersion","userDesc"],
        effectiveFieldsAlias: {
            templateId: "ID",
            templateType: "类型（0普通 1标准）",
            sourceMiniProgram: "模板小程序",
            userVersion: "版本号",
            userDesc: "描述",
        },
        data: {
            'value': (function () {
                var list = '';    // 先定义个值，方便下面赋值
                $.ajax({
                    type: 'post',
                    url: prefix+"/searchTemplateList",
                    data: {
                        pageSize: 1000,
                        pageNum: 1,
                    },
                    dataType: 'json',
                    async: false,
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            list = result.rows;
                        } else {
                            $.modal.alert(result.msg);
                        }
                    }
                });
                return list;
            })()
        }
    }).on('onSetSelectValue', function (e, keyword, data) {
        $('#templateDesc').val(data.templateId+"-"+data.sourceMiniProgram+"-"+data.userVersion);
        $('input[name="templateId"]').val(data.templateId);
        $('input[name="templateType"]').val(data.templateType);
    });

    function submitHandler() {
        if ($.validate.form()) {

            let data = $('#form-applet-commit').serializeArray();
            $.operate.save(prefix + "/commit", data);
        }
    }
</script>
</body>
</html>
